package com.activities;

import org.json.JSONException;

import com.bean.paramz;
import com.example.lizhiinformation.R;
import com.myadapter.TopicAdapter;
import com.ownload.Httputil;
import com.ownload.Httputil.OnNetWorkBitmpResponse;
import com.ownload.Httputil.OnNetWorkRespones;
import com.tools.Path_URL;
import com.tools.TopicJosn;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import com.hb.views.PinnedSectionListView;
import android.widget.TextView;
/**
 * 图片类型的详细新闻
 * @author Administrator
 *
 */
public class TopciInformation extends Activity {

	private ImageView topicimage;
	private TextView topictext;
	private PinnedSectionListView listview;
	private paramz paramz;
	private TopicAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_topci_information);
		findview();
		frame();
	}
/**
 * 初始化组件
 */
	public void findview() {
		topicimage = (ImageView) findViewById(R.id.topicimage);
		topictext = (TextView) findViewById(R.id.topictextview);
		listview = (PinnedSectionListView) findViewById(R.id.topiclistview);
	}
/**
 * 数据下载及处理
 */
	public void frame() {
		String id = getIntent().getExtras().getString("id");
		Httputil.OnWorkDown(
				"http://litchiapi.jstv.com/api/GetTopic?id="
						+ id
						+ "&val=CC065D82FE0D017649B, onNetWorkResponesC60040E7D577A====",
				new OnNetWorkRespones() {

					@Override
					public void OK(String respose) {
						// TODO Auto-generated method stub
						try {

							paramz = new TopicJosn().josn(respose);
							topictext.setText(paramz.getTopic().getContents());							
							Httputil.OnworkBitmaDown(Path_URL.IMAGEURL
									+ paramz.getTopic().getPhoto(),
									new OnNetWorkBitmpResponse() {

										@Override
										public void OK(Bitmap bitmap) {
											// TODO Auto-generated method stub
											topicimage.setImageBitmap(bitmap);
										}

										@Override
										public void ERROR(String error) {
											// TODO Auto-generated method stub

										}
									});
							adapter = new TopicAdapter(TopciInformation.this,
									paramz, listview);
							listview.setAdapter(adapter);

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

					}

					@Override
					public void ERROR(String error) {
						// TODO Auto-generated method stub

					}
				});
		listview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				//地址判断6为普通的详细新闻，4为图片类型的信息新闻
				if (adapter.getItem((int) arg3) != null) {
					switch (adapter.getItem((int) arg3).length()) {
					case 6:
						Intent intent = new Intent(TopciInformation.this,
								Front_items_activity.class);
						intent.putExtra("url", adapter.getItem((int) arg3));
						startActivity(intent);
						break;
					case 4:
						Intent intent1 = new Intent(TopciInformation.this,
								MapInformation.class);
						intent1.putExtra("url", adapter.getItem((int) arg3));
						startActivity(intent1);
						break;
					default:
						break;
					}
				}
			}
		});

	}
}
